package com.wing.sys.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wing.common.util.PageBean;
import com.wing.sys.domain.Operatelog;
import com.wing.sys.service.OperatelogManager;

/**
 * 
 * 
 * @author please  write your big name
 * 
 */
 
@Controller
@RequestMapping(value = "/sys/operatelog")
public class OperatelogController {

	@Autowired
	private OperatelogManager operatelogManager;
	
	/**
	 * 获得列表数据
	 *  
	 */
	@RequestMapping(method = RequestMethod.GET)
	public String list() {
		return "/sys/operatelog/operatelogIndex";
	}
	
	@RequestMapping(value = "get/{url}", method = RequestMethod.GET)
	public String get(@PathVariable String url) {
		return "sys/operatelog/"+url;
	}
	
	@RequestMapping(value = "list", method = RequestMethod.POST)
	public @ResponseBody PageBean list(int currentPage, String pageSize) {
		int _iPageSize = 0;
		if (pageSize == null) {
			_iPageSize = PageBean.DEFAULT_PAGESIZE;
		} else {
			_iPageSize= Integer.parseInt(pageSize);
		}
		return  operatelogManager.findPageList(currentPage, _iPageSize);
	}
	
	
	@RequestMapping(value = "toForm/{id}",method = RequestMethod.GET)
	public String toForm(@PathVariable String id,Model model) {
		Operatelog operatelog = null;
		if(!id.equals("0")){
			operatelog = operatelogManager.findById(id);
		}else{
			operatelog = new Operatelog();
		}
		model.addAttribute("operatelog", operatelog);
		return "/sys/operatelog/operatelogForm";
	}
	
	@RequestMapping(value = "save", method = RequestMethod.POST)
	public String save(Operatelog operatelog) {
		operatelogManager.saveOperatelog(operatelog);
		return "redirect:/sys/operatelog";
	}
	
	@RequestMapping(value = "deloperatelogs", method = RequestMethod.POST)
	public @ResponseBody String deloperatelogs(String[] chk) throws IOException {
		operatelogManager.deleteOperatelogs(chk);
		return ""+chk.length;
	}
}

